<?php
$field_arr = $_POST['info'];
$id = $field_arr['Id'];
$arr = array('Id');
$field_arr = arr_diff($field_arr, $arr);
if (!empty($field_arr["adminpass"])) {
	$field_arr["adminpass"] = md5($field_arr["adminpass"]);
} else {
	unset($field_arr["adminpass"]);
}



$adminid=sel_sql($table,'Id','adminname="'.$field_arr["adminname"].'"');
if ($id == '') {
    if($adminid>0){
		echo alert('管理员名重复，请更改名称');
		exit;
	}
	$field_arr["lastlogintime"] = date('Y-m-d H:i:s', time());
	$field_arr["lastloginip"] = get_client_ip();
	$field_arr["logintime"] = date('Y-m-d H:i:s', time());
	$field_arr["regtime"] = date('Y-m-d H:i:s', time());
	$field_arr["loginip"] = get_client_ip();
	insert_one_sql($table, $field_arr,0);
	admin_log('新增管理员');
	echo alert('保存成功', 'admin.php?act=list');
} else {
	$admin_id=sel_sql($table,'Id','adminname="'.$_SESSION["adminusername"].'"');
	if ($id == 1 && $admin_id!=1) {
		echo alert('不能修改默认管理员', 'admin.php?act=list');
		exit;
	} 
	if($adminid>0 && $adminid!=$id){
	    echo alert('管理员名重复，请更改名称');
		exit;
	}
	update_sql($table, $field_arr, "id=$id", 0, 0);
	admin_log('修改管理员');
	echo alert('更新成功', 'admin.php?act=list');
} 

?>
